
define(["jquery","bbcare"],function ($,$bb) {
    var servers = {};
    var URL = $bb.baseUrl("followup");
    //纠正月龄计算
    servers.correctMonthAge = function(diff,pregnancyDay){
        var monthAge,days = diff *1;
        if(pregnancyDay == 0){pregnancyDay = 280;}
        if(parseFloat(pregnancyDay) < 37*7){
            var difD = 40*7 - parseFloat(pregnancyDay); //判断与预产期差了多少天；
            days= diff - difD;
            if(days>0){
                monthAge = (days/30.4).toFixed(3);
            }else{
                monthAge = days;
            }
        }else{
            monthAge = (days/30.4).toFixed(3);
        }
        return monthAge;
    };
    /*
    *获取个人信息：
    * */
    servers.getPatientInfo = function (params , callback,otherParams){
        $bb.ajax({
            url: URL + "followup/service/patient/patientInfoPtId",
            data: JSON.stringify({
                "data": {
                    "patientId": params.userId
                }
            }),
            success: function (data) {
                if(data.success){
                    callback(data.data,otherParams);
                }else{
                    $bb.toastShow(data.msg,1500);
                }
            }
        });
    };
    /*
     * 获取题目：
     * */
    servers.getAllPostion = function (params , callback,otherParams){
        $bb.ajax({
            url: URL + "followup/service/patient/evaluation/getAllPostion",
            data: JSON.stringify({
                "data": {
                    "examinationPaperName": params.examinationPaperName,
                    "userId": params.userId
                }
            }),
            success: function (data) {
                if(data.success){
                    callback(data,otherParams);
                }else{
                    $bb.toastShow(data.msg,1500);
                }
            }
        });
    };

    /*
     *  保存结果：
     * */
    servers.saveScore = function (params,callback,otherParams){
        $bb.ajax({
            url: URL + "followup/service/patient/evaluation/getScore",
            data: JSON.stringify({
                "data": {
                    "examinationPaperName": params.examinationPaperName,
                    "postionIds": params.postionScores,
                    "userId": params.userId,
                    "postionScores": params.postionScores,
                    "taskId":params.taskId
                }
            }),
            success: function (data) {
                if(data.success){
                    callback(data.data,otherParams);
                }else{
                    $bb.toastShow(data.msg,1500);
                }
            }
        });
    };
    //获取历史记录列表：
    servers.history = function(params,callback,otherParams){
        $bb.ajax({
            url: URL + "followup/service/patient/evaluation/getHistoryScore",
            data: JSON.stringify({
                data:  {
                    "userId": params.userId,
                    "examinationPaperName": params.examinationPaperName,
                    "taskId":params.taskId
                }
            }),
            success: function (data) {
                if(data.success){
                    callback(data,otherParams);
                }else{
                    $bb.toastShow(data.msg,1500);
                }
            }
        });
    };
    return servers;
});